package com.srit.recipes.controller;


import com.srit.recipes.common.response.JpaPage;
import com.srit.recipes.common.response.Response;
import com.srit.recipes.entity.EquipmentInfo;
import com.srit.recipes.entity.InventoryHis;
import com.srit.recipes.entity.InventoryInfo;
import com.srit.recipes.service.InventoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;
import java.util.Date;

@RestController
@Api(tags = "库存-设备相关")
public class InventoryController {

    @Autowired
    private InventoryService inventoryService;


    @GetMapping("/inventory/list")
    @ApiOperation("1 查询当前库存情况, 除了分页参数只需要传name，批次号， 供应商 模糊查询")
    public Response inventoryList(JpaPage jpaPage, InventoryInfo inventoryInfo) {
        return Response.success(inventoryService.inventoryList(jpaPage, inventoryInfo));
    }

    @GetMapping("/inventory/his/list")
    @ApiOperation("2 库存历史,type 0表示入库， 1表示出库, createTime + endTime表示时间范围查询")
    public Response inventoryHis(JpaPage jpaPage, InventoryHis inventoryHis) {
        return Response.success(inventoryService.inventoryHis(jpaPage, inventoryHis));
    }


    @PostMapping("/inventory/update/in")
    @ApiOperation("3 入库")
    public Response inventoryUpdateIn(InventoryHis inventoryHis) {
        return Response.success(inventoryService.inventoryUpdateIn(inventoryHis));
    }

    @PostMapping("/inventory/update/out/{id}")
    @ApiOperation("4 出库， 出库要用库存id出库")
    public Response inventoryUpdateOut(@PathVariable int id, int wight) {
        return Response.success(inventoryService.inventoryUpdateOut(id, wight));
    }

    @GetMapping("/inventory/exceed/{type}")
    @ApiOperation("5 超期库存, type0 即将超期, type1已经超期")
    public Response inventoryExceed(JpaPage jpaPage, @PathVariable int type) {
        return Response.success(inventoryService.inventoryExceed(jpaPage, type));
    }





    @GetMapping("/equipment/list")
    @ApiOperation("6 设备查询")
    public Response equipmentList(JpaPage jpaPage, EquipmentInfo equipmentInfo) {
        return Response.success(inventoryService.equipmentList(jpaPage, equipmentInfo));
    }


    @PostMapping("/equipment/addOrUpdate")
    @ApiOperation("7 查询或者修改设备")
    public Response equipmentAddOrUpdate(EquipmentInfo equipmentInfo) {
        return Response.success(inventoryService.equipmentAddOrUpdate(equipmentInfo));
    }

    @PostMapping("/equipment/delete/{id}")
    @ApiOperation("8 删除设备")
    public Response deleteEquipment(@PathVariable int id) {
        return Response.success(inventoryService.deleteEquipment(id));
    }


    @GetMapping("/inventory/compare")
    @ApiOperation("9 入库流水与采购单偏差, date传yyyy-MM-dd格式的日期")
    public Response inventoryCompare(String date) {
        return Response.success(inventoryService.inventoryCompare(date));
    }












}
